package cpp.ece480.compteam;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class Checkout extends Activity {

	public TextView totalPrice;

	private ListView mOrdersView;

	private ArrayAdapter<String> mOrderListArrayAdapter;

	public String item;

	public int tableNumber;
	public int customerNumber;
	public int checkoutPrice;

	public boolean table1selected;
	public boolean table2selected;
	public boolean table3selected;
	public boolean table4selected;
	public boolean table5selected;
	public boolean table6selected;

	public boolean customer1selected;
	public boolean customer2selected;
	public boolean customer3selected;
	public boolean customer4selected;

	public MySQL_AndroidInterface mySQLInterface = new MySQL_AndroidInterface();

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.checkoutscreen);

		mOrderListArrayAdapter = new ArrayAdapter<String>(this,
				R.layout.message);
		mOrdersView = (ListView) findViewById(R.id.orderList);
		mOrdersView.setAdapter(mOrderListArrayAdapter);

		table1selected = ((GlobalVariable) this.getApplication()).getTable1();
		table2selected = ((GlobalVariable) this.getApplication()).getTable2();
		table3selected = ((GlobalVariable) this.getApplication()).getTable3();
		table4selected = ((GlobalVariable) this.getApplication()).getTable4();
		table5selected = ((GlobalVariable) this.getApplication()).getTable5();
		table6selected = ((GlobalVariable) this.getApplication()).getTable6();
		
		customer1selected = ((GlobalVariable) this.getApplication())
				.getCustomer1();
		customer2selected = ((GlobalVariable) this.getApplication())
				.getCustomer2();
		customer3selected = ((GlobalVariable) this.getApplication())
				.getCustomer3();
		customer4selected = ((GlobalVariable) this.getApplication())
				.getCustomer4();
		
		if (table1selected) {
			tableNumber = 1;
			if (customer1selected) {
				customerNumber = 1;
				String price = mySQLInterface.MySQL_READ2("10.0.2.2", "tables", "ordernum",
						"totalprice", "customerNum", String.valueOf(customerNumber),
						"TableNum", String.valueOf(tableNumber));
				mOrderListArrayAdapter.add("Customer 1 .... $" + price);
			//	checkoutPrice = checkoutPrice + Integer.parseInt(price);
			}
			if (customer2selected) {

			}
			if (customer3selected) {

			}
			if (customer4selected) {

			}
		}

		if (table2selected) {
			if (customer1selected) {

			}
			if (customer2selected) {

			}
			if (customer3selected) {

			}
			if (customer4selected) {

			}
		}

		if (table3selected) {
			if (customer1selected) {

			}
			if (customer2selected) {

			}
			if (customer3selected) {

			}
			if (customer4selected) {

			}
		}

		if (table4selected) {
			if (customer1selected) {

			}
			if (customer2selected) {

			}
			if (customer3selected) {

			}
			if (customer4selected) {

			}
		}

		if (table5selected) {
			if (customer1selected) {

			}
			if (customer2selected) {

			}
			if (customer3selected) {

			}
			if (customer4selected) {

			}
		}

		if (table6selected) {
			if (customer1selected) {

			}
			if (customer2selected) {

			}
			if (customer3selected) {

			}
			if (customer4selected) {

			}
		}

		totalPrice = (TextView) findViewById(R.id.totalPrice);
		// TODO Get total price
		totalPrice.setText("$" + checkoutPrice);
	}

	protected void onPause() {
		super.onPause();
	}

	protected void onResume() {
		super.onResume();
	}

	protected void onDestroy() {
		super.onDestroy();
	}

	public void print(View v) {
		Toast.makeText(this, "Printing receipt...", Toast.LENGTH_SHORT).show();
		// TODO delete table/customer info from database
		mOrderListArrayAdapter.clear();
	}

}
